package com.zyz.G_常用类.BigDecimal;

import java.math.BigDecimal;
import java.math.RoundingMode;

/**
 * @author: vick
 * @Date: 2025/3/19
 * @Description:
 * @version: 1.0
 */
public class Demo5 {
    public static void main(String[] args) {
        //单价
        BigDecimal price = new BigDecimal("9.99");

        //购买数量
        int quantity = 3;

        //税率
        BigDecimal taRate = new BigDecimal("0.08");

        //总价
        BigDecimal subtotal = price.multiply(new BigDecimal(quantity));

        //计算税额
        BigDecimal tax = subtotal.multiply(taRate).setScale(2, RoundingMode.HALF_UP);

        //最终总价
        BigDecimal total = subtotal.add(tax).setScale(2, RoundingMode.HALF_UP);

    }
}
